<!--
 * @Author: taoke
 * @Date: 2022-04-28 15:35:00
 * @LastEditors: taoke
 * @LastEditTime: 2022-05-25 08:48:02
 * @Description:
 * @FilePath: \yunying-sys-cli4\src\components\partner\invitedRecord\index.vue
-->
<template>
  <div>
    <h1 class="con-right-title">合伙人邀请记录</h1>
    <!--上部搜索条件组件-->
    <topSearch :form-inline="formInline" @toSearch="toSearch"></topSearch>
    <div class="table-conBtn">
      <el-button type="warning" icon="el-icon-download" @click="exportFile">
        导出
      </el-button>
      <freshCom @searchList="searchList"></freshCom>
    </div>
    <!-- 表格部分 -->
    <el-table v-loading="loading" :data="tableData">
      <el-table-column label="序号" type="index" width="80" align="center">
      </el-table-column>
      <el-table-column
        label="邀请人"
        prop="user.userName"
        min-width="100"
        align="center"
      >
      </el-table-column>
      <el-table-column
        label="邀请人大鹏号"
        prop="user.dpAccount"
        min-width="100"
        align="center"
      >
      </el-table-column>
      <el-table-column
        label="邀请人手机号"
        prop="user.mobile"
        min-width="100"
        align="center"
      >
      </el-table-column>
      <el-table-column
        label="被邀请人"
        prop="userBe.userName"
        min-width="100"
        align="center"
      >
      </el-table-column>
      <el-table-column
        label="被邀请人时间"
        prop="userBInTime"
        min-width="130"
        align="center"
      >
      </el-table-column>
      <el-table-column
        label="被邀请人大鹏号"
        prop="userBe.dpAccount"
        min-width="120"
        align="center"
      >
      </el-table-column>
      <el-table-column
        label="被邀请人入量手机号"
        prop="userBMobile"
        min-width="150"
        align="center"
      >
      </el-table-column>
      <el-table-column
        label="首次试学课时间"
        prop="trialCourseTime"
        min-width="130"
        align="center"
      >
      </el-table-column>
      <el-table-column
        label="当前课程状态"
        prop="courseStatus"
        min-width="100"
        align="center"
        :formatter="courseStatusFormatter"
      >
      </el-table-column>
      <el-table-column
        label="订单时间"
        prop="orderTime"
        min-width="130"
        align="center"
      >
      </el-table-column>
      <el-table-column
        label="当前订单状态"
        prop="orderStatus"
        min-width="100"
        align="center"
        :formatter="orderStatusFormatter"
      >
      </el-table-column>
      <el-table-column label="奖励金额" min-width="80" align="center">
        <template slot-scope="scope">
          <el-link target="_blank" @click="handleView(scope.row)">{{
            scope.row.bonus
          }}</el-link>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" min-width="130">
        <template slot-scope="scope">
          <template>
            <el-button type="text" @click="handleView(scope.row)">
              查看
            </el-button>
          </template>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页器 -->
    <pageCom
      :searchParams="searchParams"
      :total="total"
      @searchList="searchList"
    ></pageCom>
    <detail-dialog ref="detailDialog"></detail-dialog>
  </div>
</template>

<script>
import { formatterValueByOptions } from '@utils/table'
import {
  courseStatusOptions,
  orderStatusOptions
} from '@/components/partner/types/selectOptions'
import { getInviteRecord, downUrl } from '@/api/partner/invitedRecord'
import topSearch from './topSearch'
import detailDialog from './detailDialog'
import { tablePaginationMixin } from '@/mixins/tablePaginationMixin'
export default {
  name: 'invitedRecord',
  mixins: [tablePaginationMixin],
  components: {
    topSearch,
    detailDialog
  },
  data() {
    return {
      loading: true,
      tableData: [],
      formInline: {
        search: '', //大鹏号
        startTime: '', // 开始日期
        endTime: '', // 结束日期
        orderStatus: '', // 当前订单状态
        invitedDPAccount: '', //被邀请人大鹏号
        createTime: []
      }
    }
  },
  mounted() {
    this.searchList()
  },
  methods: {
    courseStatusFormatter(_row, _column, cellValue) {
      return formatterValueByOptions({
        cellValue,
        options: courseStatusOptions
      })
    },
    orderStatusFormatter(_row, _column, cellValue) {
      return formatterValueByOptions({
        cellValue,
        options: orderStatusOptions
      })
    },
    // 初始查询列表
    searchList() {
      this.loading = true
      const params = Object.assign(this.formInline, this.searchParams)
      getInviteRecord(
        params,
        (response) => {
          this.tableData = response.rows
          this.total = response.total
          this.loading = false
        },
        (response) => {
          this.loading = false
          this.$message({
            message: response.message,
            type: 'warning'
          })
        }
      )
    },
    handleView(row) {
      this.$refs.detailDialog.show({ row })
    },
    // 导出
    exportFile() {
      this.$confirm('确定导出合伙人邀请记录吗？', '系统提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          let url = downUrl()
          let params = this.formInline
          delete params.createTime
          this.downFile('get', url, params, '合伙人邀请记录')
        })
        .catch(() => {})
    }
  }
}
</script>
<style scoped>
.el-link {
  text-decoration: underline;
}
</style>
